//我的回答！！！！！！！！！！！！！！！！！
var isover=0;
var username;//用户中文名
var currentIndex=1;//页码
$().ready(function(){
    $.ajax({
        type: "post",
        datatype: "json",
        url:userurl,
        data:{"userId":id},
        success:function(data){
            username=data.Data.nick;
            aj();
        }
    });

});
//ba4d39d74ed0fdcb
var ajaxrunning="no";
function aj(){
    if(isover===0){
        ajaxrunning="yes";
        $.ajax({
            type:"get",
            datatype: "json",
            url: myanswerurl+"?userId="+id+"&pageSize=15&currentIndex="+currentIndex,
            success:function(data){
                console.log(data);
                if(data.Message==="没有数据"){
                    isover=1;//没有数据了
                    $("#waiting").css("display","none");
                    $("#nonews").css("display","block");
                }else{
                    if(data.Data&&data.Data.length>0){
                        if(data.Data.length<15){
                            $("#waiting").css("display","none");
                            $("#nonews").css("display","block");
                        }

                        var num=0;
                        for(var i=0;i<data.Data.length;i++){
                            num++;
                            if(num===data.Data.length){
                                ajaxrunning="no";
                            }
                            var jobname;
                            var reg=/([A-Za-z0-9\u4E00-\u9FA5])*/;
                            if(data.Data[i].user.jobs&&data.Data[i].user.jobs.length>0){
                                jobname="·"+(data.Data[i].user.jobs[0].typename).match(reg)[0];
                            }else if(!data.Data[i].user.jobs){
                                jobname="";
                            }
                            var unick1="";
                            if(data.Data[i].user){
                                if(data.Data[i].Pulu_Question.ishidename==1&&data.Data[i].user.userId!=id){
                                    unick1="匿名";
                                }else{
                                    unick1="<a href='otherpeoplepage.html?otherid="+data.Data[i].user.userId+"'>"+data.Data[i].user.nick+"</a>";
                                }
                            }
                            var count=0;
                            var tim=data.Data[i].Pulu_Question.ctime.match(/([0-9\-]+)/)[0];
                            if(data.Data[i].Pulu_Question.ctime){
                                tim=getDateDiff(getDateTimeStamp(data.Data[i].Pulu_Question.ctime));
                            };
                            if(data.Data[i].Pulu_Question.count){count=data.Data[i].Pulu_Question.count;}
                            if(data.Data[i].Pulu_Question.status===1){
                                $("#questionlist").append("<div class='pagedlist_item'><div class='feed_item feed_type_question'><div class='EventHeader'><span class='senduser'>"+unick1+"</span><span class='job'>·</span>"+tim+"</div><h2><a class='question_link' href='questiondetail.html?qid="+data.Data[i].Pulu_Question.id+"'>"+data.Data[i].Pulu_Question.title+"</a></h2><div class='ContentFooter QuestionFooter'>浏览 "+count+"&nbsp;&nbsp;&nbsp;"+"回答 "+data.Data[i].AnswerCount+"</div></div></div>")
                            }
                            if(data.Data[i].Pulu_Question.status===0){
                                $("#questionlist").append("<div class='pagedlist_item'><div class='feed_item feed_type_question'><div class='EventHeader'><span class='senduser'>"+unick1+"</span><span class='job'>·</span>"+tim+"</div><h2><a class='question_link' href='questiondetail.html?qid="+data.Data[i].Pulu_Question.id+"' id='q"+data.Data[i].Pulu_Question.id+"'>"+data.Data[i].Pulu_Question.title+"</a></h2><div class='ContentFooter QuestionFooter'>回答 "+data.Data[i].AnswerCount+"</div></div></div>")
                            }
                        }
                    }
                    else{
                        $("#waiting").css("display","none");
                        $("#nonews").css("display","block");
                    }
                }

            }
        })
    }

}
$(window).scroll(function(){
    var mainheight=$(".home_feed").height();
    //console.log("加载区域高度："+mainheight);
    var windowheight=$(window).height();
    //console.log("窗口高度："+windowheight);
    var what=$(".home_feed").offset().top;
    var chajuli=$(".home_feed").offset().top - $(window).scrollTop();
    var cz=windowheight-mainheight+50;
    //console.log("窗口与加载差值："+cz);
    //console.log("差值"+chajuli);
    if(chajuli<cz&&ajaxrunning==="no"){
        currentIndex++;
        aj();
    }
});
//搜索
document.onkeydown=function(event){
    var e = event || window.event || arguments.callee.caller.arguments[0];
    if(e && e.keyCode==13){ // enter 键
        var word=document.getElementById("searchinput").value;
        if(word){
            if(word.match(/^\s+$/g)){
                console.log("没有填信息")
            }else{
                location.href="search.html?searchKey="+word;
            }
        }
    }
};
document.getElementById("gotosearch").onclick=function(){
    var word=document.getElementById("searchinput").value;
    if(word){
        if(word.match(/^\s+$/g)){
            console.log("没有填信息")
        }else{
            location.href="search.html?searchKey="+word;
        }
    }
};